#ifndef UTIL_H_INCLUDED
#define UTIL_H_INCLUDED

#define MIN(a, b) a < b ? a : b;
#define MAX(a, b) a > b ? a : b;

void sys_error(const char* msg);
void fatal(const char* fmt, ...);
#include <iostream>

template <uint8_t numBits, typename T >
std::ostream& bin(T& value, std::ostream &o)
{
    T bit = 1 << (numBits - 1);
    for(uint8_t i = numBits - 1; i != (uint8_t)-1; i--)
    {
        o << (( value & bit ) ? '1' : '0' );
        bit >>= 1;
    }

    return o;
}

#endif // UTIL_H_INCLUDED
